
<?php include './application/views/top.php'; ?>
<script src="/resource/js/circle-progress.js"></script>


<div class="clear h50"></div>
<div class="layout reg">

	<div class="bar"><span>登录 > 找回密码</span></div>

	<div class="mb">
		<div class="lb">
        <input type="radio" name="type" value="mail" onclick="phoneOrMail(this);" checked="checked" class="anniu">
		<label>邮箱</label>
        <input type="radio" name="type" value="phone" onclick="phoneOrMail(this);" class="anniu">
		<label>手机</label>
		</div>
        <div class="clear h10"></div>
		<form id="mail_form">
        <input type="hidden" name="act" value="mail">
		<div class="lb">
			<i>*</i>
			<span>邮&nbsp;&nbsp;&nbsp;箱：</span>
            <input class="search_k" name="email" id="email" type="text" value="请输入邮箱" onfocus="clearText(this);" onblur="setText(this,'请输入邮箱');">
		</div>
		<div class="lb">
			<i>*</i>
			<span>用户名：</span>
            <input class="search_k" name="username" id="username" type="text" value="请输入用户名" onfocus="clearText(this);" onblur="setText(this,'请输入用户名');">
		</div>
		<div class="lb">
			<i>*</i>
			<span>验证码：</span>
            <input class="search_k" type="text" id="captcha" name="captcha" maxlength="4">
			<b><img src="/yanzheng/index/" id="imgCode" onclick="changeImage();" /></b>
		</div>
		<div class="tishi">请输入图中字符，不区分大小写</div>
		<div class="nul"><a href="javascript:void();" class="ljtb_a" onclick="toSubmit('mail_form');">马上找回</a></div>
		
        <div class="dian">*</div>
        <div class="text">还没有加入<?php echo CON_PLATFORMNAME;?>？<a href="/reg/index/index.html">免费注册</a></div>
        </form>
        <form id="phone_form" style="display: none;">
		<div class="lb">
			<i>*</i>
			<span>手&nbsp;&nbsp;&nbsp;机：</span>
            <input class="search_k" name="phone" id="phone" type="text" value="请输入手机" onfocus="clearText(this);" onblur="setText(this,'请输入手机');">
		</div>
		<div class="lb">
			<i>*</i>
			<span>用户名：</span>
            <input class="search_k" name="username" id="username" type="text" value="请输入用户名" onfocus="clearText(this);" onblur="setText(this,'请输入用户名');">
		</div>
		<div class="lb">
			<i>*</i>
			<span>新密码：</span>
            <input class="search_k" name="new_password" id="new_password" type="password">
		</div>
		<div class="lb">
			<i>*</i>
			<span>验证码：</span>
            <input class="search_p" type="text" id="captcha" name="captcha" maxlength="6">
			<b><a href="javascript:;" onclick="phoneSubmit(12);" id="phone_code"> 获取验证码</a></b>
		</div>
        <div class="clear h30"></div>
		<div class="nul"><a href="javascript:void();" class="ljtb_a" onclick="toSubmit('phone_form');">马上找回</a></div>
		
        <div class="dian">*</div>
        <div class="text">还没有加入<?php echo CON_PLATFORMNAME;?>？<a href="/reg/index/index.html">免费注册</a></div>
		</form>
	</div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script type="text/javascript">
function clearText(input){
	if(input.value=='请输入用户名' || input.value=='请输入邮箱' || input.value=='请输入手机' || input.value=='请输入新密码'){
		input.value="";
	}
}

function setText(input,txt){
	if(input.value==''){
		input.value=txt;
	}
}

function phoneOrMail(radio){
    if(radio.value == 'mail'){
        $('#phone_form').css('display','none');
        $('#mail_form').css('display','block');
    }
    if(radio.value == 'phone'){
        $('#mail_form').css('display','none');
        $('#phone_form').css('display','block');
    }
}

function phoneSubmit($id){
    if($('#phone').val()=='' || $("#phone").val() == "请输入手机号码"){
        $('#dialog').dialog({
            modal:true, //蒙层（弹出会影响页面大小）
            title:'系统提示',
            buttons:{"确定":function(){$(this).dialog("close");}},
            close: function() {
            }
        });
        $("#msg").html("请输入手机号码");
        $("#phone").focus();
        return false;
    }else{
        $.ajax({
            type: "post",
            url: "/reg/apply_phone/"+$id,
            data: "phone="+$("#phone").val(),
            success: function(ret){
                //$("#phone_code").html(ret.msg);
                if(ret.info == 1){
                    phone_countdown();

                }else{
                    $('#dialog').dialog({
                        modal:true, //蒙层（弹出会影响页面大小）
                        title:'系统提示',
                        buttons:{"确定":function(){$(this).dialog("close");}},
                        close: function() {
                        }
                    });
                    $("#msg").html(ret.msg);
                }


            },
            dataType: "json"
        });
    }

}


function phone_countdown(){
    var count = 60;
    var countdown = setInterval(CountDown, 1000);

    function CountDown() {
        $("#phone_code").html('<font style="color:#FFF;">'+count+"</font>秒后重试");
        if (count == 0) {
            $("#phone_code").html('获取验证码');
            clearInterval(countdown);
        }
        count--;
    }

}

function toSubmit(form){
	var options = {
		url : '/password/forget',
		clearForm :true,
		resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			$('#dialog').dialog({
				modal:true,
				title:'系统提示',
				buttons:{"确定":function(){$(this).dialog("close");}},
				close: function() {
					document.getElementById("imgCode").src = "/yanzheng/index/?" + Math.random();
				}
			}); 
			$("#msg").html(ret.msg);
            if(ret.skip == 1){
                setTimeout(function(){location='/login';},3000);
            }

		}
	};
    console.log(form);
    if(form == 'mail_form'){
        $("#mail_form").ajaxSubmit(options);
    }
    if(form == 'phone_form'){
        $("#phone_form").ajaxSubmit(options);
    }
	return false;
}

function checkForm(){
	//return true;
	var err = '';
//	if($('#email').val()=='' || $('#email').val()=='请输入邮箱'){
//		err = '请输入邮箱';
//	}else
//    if($('#username').val()==''||$('#username').val()=='请输入用户名'){
//		err = '请输入用户名';
//	}else if($('#captcha').val()==''){
//		err = '请输入验证码';
//	}
	if(err==''){
		return true;
	}else{
		$('#dialog').dialog({
			modal:true,
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}},
			close: function() {
				document.getElementById("imgCode").src = "/yanzheng/index/?" + Math.random();
			}
		}); 
		$("#msg").html(err);
		return false;
	}
}

</script>